package com.baizhi.controller;

import com.baizhi.entity.Category;
import com.baizhi.service.CategoryService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@RequestMapping("Cate")
public class CategoryController {

    @Resource
    CategoryService categoryService;

    @RequestMapping("queryOneCatePage")
    public HashMap<String , Object> queryOneCatePage(Integer page, Integer rows){
        return categoryService.queryOneCatePage(page, rows);
    }

    @RequestMapping("queryTwoCatePage")
    public HashMap<String , Object> queryTwoCatePage(Integer page, Integer rows,String parentId){
        return categoryService.queryTwoCatePage(page, rows, parentId);
    }

    @RequestMapping("edit")
    public HashMap<String , Object> edit(Category category,String parentId,String oper){
        HashMap<String, Object> map = new HashMap<>();

        if(oper.equals("edit")){
            categoryService.update(category);
        }
        if(oper.equals("del")){
            map = categoryService.del(category);
        }
        if(oper.equals("add")){
            categoryService.add(category);
        }
        return map;
    }
}
